import { Action, createReducer, on } from '@ngrx/store';
import {createEntityAdapter, EntityAdapter, EntityState} from "@ngrx/entity";
import {add, del} from "../actions/memo.actions";

export const MemoFeatureKey = 'Memo';

export interface Memo {
    id: string;
    name: string;
}

export interface State extends EntityState<Memo>{

}

export const adapter: EntityAdapter<Memo> = createEntityAdapter<Memo>();
export const initialState: State = adapter.getInitialState();

export const reducer = createReducer(
    initialState,
    on(add, (state,action:any)=> adapter.addOne({id:'1',name:action.name},state)),
     on(del, (state,action:any)=> adapter.removeOne(action.id, state))
);
